package info.techgeek.labs.java5Features.thread.pripority;

import java.util.concurrent.PriorityBlockingQueue;

public class NormalExecutor {
    PriorityBlockingQueue<SamplePriorityTask> _queue = new PriorityBlockingQueue<SamplePriorityTask>(1000);
    
    public void submitTask(SamplePriorityTask task){
            _queue.offer(task);
    }
    
    public void start(){
            for (int i = 0;i<6 ; i++){
                    Thread thread = new Thread(new Runnable(){

//                            @Override
                            public void run() {
                                    
                                    while(true){
                                            try {
                                             PriorityTask task = _queue.take();
                                                    if (task != null) task.run();
                                            } catch (InterruptedException e) {
                                                    Thread.interrupted();
                                            }
                                    }
                            }
                            
                    },"TREAD" + i);
                    thread.start();
                    System.out.println("TREAD" + i + " started");
            }
    }
}

